package com.gxar.quick.ar.server.base.model.protocol.common;

import com.gxar.quick.ar.server.base.common.enums.protocol.*;

import java.util.List;

import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;

public class CommonArProtocolAssertUtil {

    private CommonArProtocolAssertUtil() {
        // Nothing
    }

    /**
     * 通用检查
     *
     * @param commonArProtocol
     */
    public static void assertProtocol(CommonArProtocol commonArProtocol) {
        assertThat(commonArProtocol, notNullValue());

        if (ArProtocolEditorEnum.WEB_EDITOR.equals(commonArProtocol.getEditor())) {
            assertThat(commonArProtocol.getVersion(), notNullValue());
        }
        assertThat(commonArProtocol.getProductMethod(), notNullValue());
        assertThat(commonArProtocol.getWorkId(), notNullValue());
        assertThat(commonArProtocol.getDisplayMode(), notNullValue());
        assertThat(commonArProtocol.getSpaceBaseSize(), notNullValue());
//        assertThat(commonArProtocol.getWaterMark(), notNullValue());

        assertImageIdentifyModel((CommonArImageIdentifyModel) commonArProtocol.getIdentifyModel());

        assertContentModels(commonArProtocol.getEditor(), commonArProtocol.getContentModelList());
    }

    public static void assertImageIdentifyModel(CommonArImageIdentifyModel identifyModel) {
        assertThat(identifyModel, notNullValue());
        assertThat(identifyModel.getWorldSize(), notNullValue());
        assertThat(identifyModel.getOriginSize(), notNullValue());
        assertThat(identifyModel.getLinkUrl(), notNullValue());
        assertThat(identifyModel.getScale(), notNullValue());
        assertThat(identifyModel.getPosition(), notNullValue());
        assertThat(identifyModel.getRotation(), notNullValue());
        assertThat(identifyModel.getShowIdentify(), notNullValue());
    }

    public static void assertBorderModel(CommonArItemBorderModel borderModel) {
        assertThat(borderModel, notNullValue());
        assertThat(borderModel.getId(), notNullValue());
        assertThat(borderModel.getType(), notNullValue());
        assertThat(borderModel.getType(), equalTo(ArWebEditorContentTypeEnum.IMAGE.getName()));
        assertThat(borderModel.getSubType(), notNullValue());
        assertThat(borderModel.getSubType(), equalTo(ArContentSubTypeEnum.DEFAULT));
        assertThat(borderModel.getLinkType(), nullValue());
        assertThat(borderModel.getLinkUrl(), notNullValue());
        assertThat(borderModel.getIs3dItem(), notNullValue());
        assertThat(borderModel.getFillType(), notNullValue());
        assertThat(borderModel.getIsBorder(), equalTo(true));
        assertThat(borderModel.getAlphaMode(), equalTo(ArAlphaMode.BLEND.getName()));
        assertThat(borderModel.getEffect(), equalTo(ArEffectEnum.DEFAULT));
        assertThat(borderModel.getInnerX(), notNullValue());
        assertThat(borderModel.getInnerY(), notNullValue());
        assertThat(borderModel.getInnerWidth(), notNullValue());
        assertThat(borderModel.getInnerHeight(), notNullValue());
        assertThat(borderModel.getScale(), notNullValue());
        assertThat(borderModel.getPosition(), notNullValue());
        assertThat(borderModel.getRotation(), notNullValue());
        assertThat(borderModel.getWorldSize(), nullValue());  // ?
        assertThat(borderModel.getOriginSize(), nullValue()); // ?
        assertThat(borderModel.getQuaternion(), nullValue()); // 边框没有四元素
    }

    public static void assertContentModels(ArProtocolEditorEnum editor, List<CommonArContentModel> contentModels) {
        assertThat(contentModels, notNullValue());
        assertThat(editor, notNullValue());
        assertThat(!contentModels.isEmpty(), equalTo(true));

        contentModels.stream().forEach(contentItem -> {
            assertThat(contentItem, notNullValue());
            assertThat(contentItem.getId(), notNullValue());
            assertThat(contentItem.getType(), notNullValue());
            assertThat(contentItem.getSubType(), notNullValue());
            if (!ArUnityEditorContentTypeEnum.DIR_LIGHT.getName().equals(contentItem.getType())) {
//                assertThat(contentItem.getLinkType(), notNullValue());
                assertThat(contentItem.getLinkUrl(), notNullValue());
            }
            if (ArProtocolEditorEnum.WEB_EDITOR.equals(editor)) {
                assertThat(contentItem.getWorldSize(), notNullValue());
                assertThat(contentItem.getOriginSize(), notNullValue());
            }
            assertThat(contentItem.getIs3dItem(), notNullValue());
            assertThat(contentItem.getPosition(), notNullValue());
            assertThat(contentItem.getScale(), notNullValue());
            assertThat(contentItem.getRotation(), notNullValue());
            assertThat(contentItem.getQuaternion(), notNullValue());
            assertThat(contentItem.getFillType(), notNullValue());
            assertThat(contentItem.getIsBorder(), notNullValue());
            assertThat(contentItem.getAlphaMode(), notNullValue());
            assertThat(contentItem.getEffect(), notNullValue());
//            assertThat(contentItem.getAnimation(), nullValue());
            assertThat(contentItem.getHasBorder(), notNullValue());

            if (contentItem.getHasBorder()) {
                CommonArItemBorderModel borderModel = contentItem.getBorder();
                assertBorderModel(borderModel);
            }
        });
    }
}
